﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类t_Business_LitigationInfo。
    /// </summary>
    public class t_Business_LitigationInfo
    {
        public t_Business_LitigationInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(Guid RecordId)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_Business_LitigationInfo where RecordId=@RecordId ");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Business_LitigationInfo(");
            strSql.Append("RecordId,ContractId,ContractCode,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AppDate,LitigationMoney,LitigationPerson,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,Status,ApproveDepartId,ApproveDepart,ApproveEmployeeId,ApproveEmployee,ApproveReason,Suggestion,ApproveOprEmpId,ApproveOprEmp,ApproveOprTime,RulingMode,SettledMoney,CurrentTrialStatus)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@ContractId,@ContractCode,@HouseAddress,@AppCityId,@AppCity,@AppCompanyId,@AppCompany,@AppDepartId,@AppDepart,@AppDate,@LitigationMoney,@LitigationPerson,@AddTime,@AddEmployeeId,@AddEmployee,@AddDepartId,@AddDepart,@Status,@ApproveDepartId,@ApproveDepart,@ApproveEmployeeId,@ApproveEmployee,@ApproveReason,@Suggestion,@ApproveOprEmpId,@ApproveOprEmp,@ApproveOprTime,@RulingMode,@SettledMoney,@CurrentTrialStatus)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode);
            db.AddInParameter(dbCommand, "HouseAddress", DbType.AnsiString, model.HouseAddress);
            db.AddInParameter(dbCommand, "AppCityId", DbType.Guid, model.AppCityId);
            db.AddInParameter(dbCommand, "AppCity", DbType.AnsiString, model.AppCity);
            db.AddInParameter(dbCommand, "AppCompanyId", DbType.Guid, model.AppCompanyId);
            db.AddInParameter(dbCommand, "AppCompany", DbType.AnsiString, model.AppCompany);
            db.AddInParameter(dbCommand, "AppDepartId", DbType.Guid, model.AppDepartId);
            db.AddInParameter(dbCommand, "AppDepart", DbType.AnsiString, model.AppDepart);
            db.AddInParameter(dbCommand, "AppDate", DbType.DateTime, model.AppDate);
            db.AddInParameter(dbCommand, "LitigationMoney", DbType.Decimal, model.LitigationMoney);
            db.AddInParameter(dbCommand, "LitigationPerson", DbType.AnsiString, model.LitigationPerson);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "AddEmployeeId", DbType.Guid, model.AddEmployeeId);
            db.AddInParameter(dbCommand, "AddEmployee", DbType.AnsiString, model.AddEmployee);
            db.AddInParameter(dbCommand, "AddDepartId", DbType.Guid, model.AddDepartId);
            db.AddInParameter(dbCommand, "AddDepart", DbType.AnsiString, model.AddDepart);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.AddInParameter(dbCommand, "ApproveDepartId", DbType.Guid, model.ApproveDepartId);
            db.AddInParameter(dbCommand, "ApproveDepart", DbType.AnsiString, model.ApproveDepart);
            db.AddInParameter(dbCommand, "ApproveEmployeeId", DbType.Guid, model.ApproveEmployeeId);
            db.AddInParameter(dbCommand, "ApproveEmployee", DbType.AnsiString, model.ApproveEmployee);
            db.AddInParameter(dbCommand, "ApproveReason", DbType.AnsiString, model.ApproveReason);
            db.AddInParameter(dbCommand, "Suggestion", DbType.AnsiString, model.Suggestion);
            db.AddInParameter(dbCommand, "ApproveOprEmpId", DbType.Guid, model.ApproveOprEmpId);
            db.AddInParameter(dbCommand, "ApproveOprEmp", DbType.AnsiString, model.ApproveOprEmp);
            db.AddInParameter(dbCommand, "ApproveOprTime", DbType.DateTime, model.ApproveOprTime);
            db.AddInParameter(dbCommand, "RulingMode", DbType.AnsiString, model.RulingMode);
            db.AddInParameter(dbCommand, "SettledMoney", DbType.Decimal, model.SettledMoney);
            db.AddInParameter(dbCommand, "CurrentTrialStatus", DbType.Int32, model.CurrentTrialStatus);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_Business_LitigationInfo set ");
            strSql.Append("ContractId=@ContractId,");
            strSql.Append("ContractCode=@ContractCode,");
            strSql.Append("HouseAddress=@HouseAddress,");
            strSql.Append("AppCityId=@AppCityId,");
            strSql.Append("AppCity=@AppCity,");
            strSql.Append("AppCompanyId=@AppCompanyId,");
            strSql.Append("AppCompany=@AppCompany,");
            strSql.Append("AppDepartId=@AppDepartId,");
            strSql.Append("AppDepart=@AppDepart,");
            strSql.Append("AppDate=@AppDate,");
            strSql.Append("LitigationMoney=@LitigationMoney,");
            strSql.Append("LitigationPerson=@LitigationPerson,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("AddEmployeeId=@AddEmployeeId,");
            strSql.Append("AddEmployee=@AddEmployee,");
            strSql.Append("AddDepartId=@AddDepartId,");
            strSql.Append("AddDepart=@AddDepart,");
            strSql.Append("Status=@Status,");
            strSql.Append("ApproveDepartId=@ApproveDepartId,");
            strSql.Append("ApproveDepart=@ApproveDepart,");
            strSql.Append("ApproveEmployeeId=@ApproveEmployeeId,");
            strSql.Append("ApproveEmployee=@ApproveEmployee,");
            strSql.Append("ApproveReason=@ApproveReason,");
            strSql.Append("Suggestion=@Suggestion,");
            strSql.Append("ApproveOprEmpId=@ApproveOprEmpId,");
            strSql.Append("ApproveOprEmp=@ApproveOprEmp,");
            strSql.Append("ApproveOprTime=@ApproveOprTime,");
            strSql.Append("RulingMode=@RulingMode,");
            strSql.Append("SettledMoney=@SettledMoney,");
            strSql.Append("CurrentTrialStatus=@CurrentTrialStatus");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode);
            db.AddInParameter(dbCommand, "HouseAddress", DbType.AnsiString, model.HouseAddress);
            db.AddInParameter(dbCommand, "AppCityId", DbType.Guid, model.AppCityId);
            db.AddInParameter(dbCommand, "AppCity", DbType.AnsiString, model.AppCity);
            db.AddInParameter(dbCommand, "AppCompanyId", DbType.Guid, model.AppCompanyId);
            db.AddInParameter(dbCommand, "AppCompany", DbType.AnsiString, model.AppCompany);
            db.AddInParameter(dbCommand, "AppDepartId", DbType.Guid, model.AppDepartId);
            db.AddInParameter(dbCommand, "AppDepart", DbType.AnsiString, model.AppDepart);
            db.AddInParameter(dbCommand, "AppDate", DbType.DateTime, model.AppDate);
            db.AddInParameter(dbCommand, "LitigationMoney", DbType.Decimal, model.LitigationMoney);
            db.AddInParameter(dbCommand, "LitigationPerson", DbType.AnsiString, model.LitigationPerson);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "AddEmployeeId", DbType.Guid, model.AddEmployeeId);
            db.AddInParameter(dbCommand, "AddEmployee", DbType.AnsiString, model.AddEmployee);
            db.AddInParameter(dbCommand, "AddDepartId", DbType.Guid, model.AddDepartId);
            db.AddInParameter(dbCommand, "AddDepart", DbType.AnsiString, model.AddDepart);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.AddInParameter(dbCommand, "ApproveDepartId", DbType.Guid, model.ApproveDepartId);
            db.AddInParameter(dbCommand, "ApproveDepart", DbType.AnsiString, model.ApproveDepart);
            db.AddInParameter(dbCommand, "ApproveEmployeeId", DbType.Guid, model.ApproveEmployeeId);
            db.AddInParameter(dbCommand, "ApproveEmployee", DbType.AnsiString, model.ApproveEmployee);
            db.AddInParameter(dbCommand, "ApproveReason", DbType.AnsiString, model.ApproveReason);
            db.AddInParameter(dbCommand, "Suggestion", DbType.AnsiString, model.Suggestion);
            db.AddInParameter(dbCommand, "ApproveOprEmpId", DbType.Guid, model.ApproveOprEmpId);
            db.AddInParameter(dbCommand, "ApproveOprEmp", DbType.AnsiString, model.ApproveOprEmp);
            db.AddInParameter(dbCommand, "ApproveOprTime", DbType.DateTime, model.ApproveOprTime);
            db.AddInParameter(dbCommand, "RulingMode", DbType.AnsiString, model.RulingMode);
            db.AddInParameter(dbCommand, "SettledMoney", DbType.Decimal, model.SettledMoney);
            db.AddInParameter(dbCommand, "CurrentTrialStatus", DbType.Int32, model.CurrentTrialStatus);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_Business_LitigationInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Business_LitigationInfo GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,ContractCode,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AppDate,LitigationMoney,LitigationPerson,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,Status,ApproveDepartId,ApproveDepart,ApproveEmployeeId,ApproveEmployee,ApproveReason,Suggestion,ApproveOprEmpId,ApproveOprEmp,ApproveOprTime,RulingMode,SettledMoney,CurrentTrialStatus from t_Business_LitigationInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,ContractCode,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AppDate,LitigationMoney,LitigationPerson,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,Status,ApproveDepartId,ApproveDepart,ApproveEmployeeId,ApproveEmployee,ApproveReason,Suggestion,ApproveOprEmpId,ApproveOprEmp,ApproveOprTime,RulingMode,SettledMoney,CurrentTrialStatus ");
            strSql.Append(" FROM t_Business_LitigationInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetList(int PageIndex, int PageSize, String OrderField, string TableName, string StrWhere, string FieldList, string TableFieldList, bool DoCount)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("PagerMultiTable");
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "OrderField", DbType.AnsiString, OrderField);
            db.AddInParameter(dbCommand, "TableName", DbType.AnsiString, TableName);
            db.AddInParameter(dbCommand, "StrWhere", DbType.AnsiString, StrWhere);
            db.AddInParameter(dbCommand, "FieldList", DbType.AnsiString, FieldList);
            db.AddInParameter(dbCommand, "TableFieldList", DbType.AnsiString, TableFieldList);
            db.AddInParameter(dbCommand, "DoCount", DbType.Boolean, DoCount);
            return db.ExecuteDataSet(dbCommand);
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
            db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "t_Business_LitigationInfo");
            db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
            return db.ExecuteDataSet(dbCommand);
        }*/

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Business_LitigationInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,ContractCode,HouseAddress,AppCityId,AppCity,AppCompanyId,AppCompany,AppDepartId,AppDepart,AppDate,LitigationMoney,LitigationPerson,AddTime,AddEmployeeId,AddEmployee,AddDepartId,AddDepart,Status,ApproveDepartId,ApproveDepart,ApproveEmployeeId,ApproveEmployee,ApproveReason,Suggestion,ApproveOprEmpId,ApproveOprEmp,ApproveOprTime,RulingMode,SettledMoney,CurrentTrialStatus ");
            strSql.Append(" FROM t_Business_LitigationInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Business_LitigationInfo> list = new List<Chenxin.Lib.Business.Entity.t_Business_LitigationInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Business_LitigationInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model = new Chenxin.Lib.Business.Entity.t_Business_LitigationInfo();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["ContractId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractId = new Guid(ojb.ToString());
            }
            model.ContractCode = dataReader["ContractCode"].ToString();
            model.HouseAddress = dataReader["HouseAddress"].ToString();
            ojb = dataReader["AppCityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AppCityId = new Guid(ojb.ToString());
            }
            model.AppCity = dataReader["AppCity"].ToString();
            ojb = dataReader["AppCompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AppCompanyId = new Guid(ojb.ToString());
            }
            model.AppCompany = dataReader["AppCompany"].ToString();
            ojb = dataReader["AppDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AppDepartId = new Guid(ojb.ToString());
            }
            model.AppDepart = dataReader["AppDepart"].ToString();
            ojb = dataReader["AppDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AppDate = (DateTime)ojb;
            }
            ojb = dataReader["LitigationMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LitigationMoney = (decimal)ojb;
            }
            model.LitigationPerson = dataReader["LitigationPerson"].ToString();
            ojb = dataReader["AddTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddTime = (DateTime)ojb;
            }
            ojb = dataReader["AddEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddEmployeeId = new Guid(ojb.ToString());
            }
            model.AddEmployee = dataReader["AddEmployee"].ToString();
            ojb = dataReader["AddDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddDepartId = new Guid(ojb.ToString());
            }
            model.AddDepart = dataReader["AddDepart"].ToString();
            ojb = dataReader["Status"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Status = (int)ojb;
            }
            ojb = dataReader["ApproveDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ApproveDepartId = new Guid(ojb.ToString());
            }
            model.ApproveDepart = dataReader["ApproveDepart"].ToString();
            ojb = dataReader["ApproveEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ApproveEmployeeId = new Guid(ojb.ToString());
            }
            model.ApproveEmployee = dataReader["ApproveEmployee"].ToString();
            model.ApproveReason = dataReader["ApproveReason"].ToString();
            model.Suggestion = dataReader["Suggestion"].ToString();
            ojb = dataReader["ApproveOprEmpId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ApproveOprEmpId = new Guid(ojb.ToString());
            }
            model.ApproveOprEmp = dataReader["ApproveOprEmp"].ToString();
            ojb = dataReader["ApproveOprTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ApproveOprTime = (DateTime)ojb;
            }
            model.RulingMode = dataReader["RulingMode"].ToString();
            ojb = dataReader["SettledMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SettledMoney = (decimal)ojb;
            }
            ojb = dataReader["CurrentTrialStatus"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CurrentTrialStatus = (int)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}

